import 'package:flutter/material.dart';
import 'package:tarantulas/goodlook/GoodLookPages.dart';
class GoodLook extends StatefulWidget {
  @override
  _GoodLookState createState() => _GoodLookState();
}

class _GoodLookState extends State<GoodLook> with SingleTickerProviderStateMixin{

  TabController _tabController;
  var brotherCategory = ['最新', '物业风采', '推荐', '热点', '3C科技','爱生活', '汽车', '明星八卦'];
  var currentIndex = 0;

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(
        initialIndex: currentIndex, length: brotherCategory.length, vsync: this)
      ..addListener(() {});
  }

  @override
  Widget build(BuildContext context) {
    return getCategoryView();
  }

  Widget getCategoryView() {
    return Scaffold(
      appBar: AppBar(
          title: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
            Icon(Icons.search,color: Colors.grey,),
            SizedBox(width: 10,),
            Text('搜索',style: TextStyle(fontSize: 15,color: Colors.grey),),
            
          ],),
          centerTitle: true,
          bottom: PreferredSize(
              child: Material(
                color: Colors.white,
                child: TabBar(
                  isScrollable: true,
                  controller: _tabController,
                  tabs: getTabBars(),
                  indicatorColor: Colors.transparent,
                  unselectedLabelColor: Colors.black,
                  labelColor: Color(0xff23AFDC),),
              ),
              preferredSize: Size.fromHeight(48))

      ),
      body: TabBarView(
        children: getTabBarViews(),
        controller: _tabController,
      ),
    );
  }

  List<Widget> getTabBars() {
    List<Widget> tabBar = List();
    for (int i = 0; i < brotherCategory.length; i++) {
      tabBar.add(Tab(text: brotherCategory[i]));
    }
    return tabBar;
  }

  List<Widget> getTabBarViews() {
    List<Widget> tabBarView = List();
    for (var i = 0; i < brotherCategory.length; i++) {
      tabBarView.add(GoodLookPages());
    }
    return tabBarView;
  }
}
